﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Foothill.Service.Validation
{
    public class StringGenerator : IStringGenerator
    {
        private readonly Random _random = new Random();

        private const string _chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

        private const string _digits = "0123456789";
        
        public Guid GenerateRegistrationConfirmationCode()
        {
            return Guid.NewGuid();
        }

        public string GenerateTempPassword()
        {
            return string.Format("{0}{1}", RandomString(5, _chars), RandomString(3, _digits));
        }

        internal string RandomString(int size, string source)
        {
            char[] buffer = new char[size];

            for (int i = 0; i < size; i++)
            {
                buffer[i] = source[_random.Next(source.Length)];
            }

            return new string(buffer);
        }
    }
}
